package com.dingcan.biao1;

import java.io.*;
import java.util.Properties;

public class ConfigMange {

    static Properties properties =null;
    static  ConfigMange configMange =null;

    /*创建 ConfigMange 对象的构造方法*/
    public  ConfigMange(String path) throws IOException {
        properties = new Properties();
        File file = new File(path);
        InputStream inputStream = new FileInputStream(file);
        properties.load(inputStream);
    }

    /*利用构造方法创建 ConfigMange实例*/
    public static ConfigMange getConfig(String path) {
        try {
            if(configMange == null){
                configMange =new ConfigMange(path);
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return  configMange;
    }


    /*获取配置文件的属性*/
    public static String getValue(String key){
        if(properties !=null){
            return   properties.getProperty(key);
        }else {
            return "没有该属性";
        }
    }

}
